﻿@model WaiGaoQiaoWeb.Models.OutstockGroupDetailedVM
@{
    ViewBag.Title = "食材出库管理";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@section Head
{
    @Html.Css("EditForm", "RightSeparateModule", "dp")
    @Html.Js("datepicker")
    <script src="../../Scripts/datepicker-zh.js" type="text/javascript"></script>
    <script type="text/javascript">
        var mainheight = document.documentElement.clientHeight;
        var mainWidth = document.documentElement.clientWidth; // 减去左边的宽度
        $(document).ready(function () {
            $("#instockDt").datepicker({ dateFormat: 'yy-mm-dd' });
            $("#endDt").datepicker({ dateFormat: 'yy-mm-dd' });
            var otherpm = $("#title").height() + $("#findDiv").height(); // 290;
            var gh = mainheight - otherpm - 80;
            var option = {
                height: gh,
                width: mainWidth,
                url: '@Url.Action("GetDetailList")',
                dataType: 'json',
                colModel: [
					{ display: '编号', name: 'ID', width: 100, sortable: false, hide: true, align: 'left', iskey: true },
                    { display: '出库日期', name: 'OutstockDt', width: 120, sortable: false, hide: false, align: 'left' },
					{ display: '仓库', name: 'Warehouse_ID', width: 100, sortable: false, hide: false, align: 'left' },
                    { display: '班组', name: 'Group_Id', width: 80, sortable: false, hide: false, align: 'left' },
                    { display: '食材', name: 'Goods_Id', width: 100, sortable: false, hide: false, align: 'left' },
                    { display: '数量', name: 'Count', width: 100, sortable: false, hide: false, align: 'left' },
                    { display: '单价', name: 'Price', width: 80, sortable: false, align: 'left' },
				    { display: '金额', name: 'Amount', width: 100, sortable: false, hide: false, align: 'left' },
                    { display: '领用人', name: 'LeadMan', width: 100, sortable: false, hide: false, align: 'left' },
                    { display: '记录日期', name: 'RecordDateTime', width: 120, sortable: false, hide: true, align: 'left' },
                    { display: '操作人', name: 'OperatorID', width: 100, sortable: false, hide: true, align: 'left' },
                    { display: '订单号', name: 'OrderNo', width: 120, sortable: false, hide: true, align: 'left' }
				],
                buttons: [
							{ name: 'Add', displayname: "新建", title: "添加食材出库", bclass: 'add', onpress: toolbarItem_onclick },
							{ name: 'Edit', displayname: "修改", title: "修改食材出库", bclass: 'edit', onpress: toolbarItem_onclick },
                            { name: 'Delete', displayname: "删除", title: "删除食材出库", bclass: 'delete', onpress: toolbarItem_onclick },
                            { separator: true }
						 ],

                title: false,
                singleselected: false,
                usepager: true,
                page: 1, //默认当前页  
                total: 1, //总页面数  
                useRp: true, //是否可以动态设置每页显示的结果数  
                rp: 20, // 每页默认的结果数  
                rpOptions: [10, 15, 20], //可选择设定的每页结果数
                showcheckbox: true,
                selectedonclick: true,
                //rowhandler: singleclick, //是否启用行的扩展事情功能,在生成行时绑定事件，如双击，右键等
                //onToggleCol: dblClick, //当在行之间转换时
                rowbinddata: true
            };
            var grid = $("#OutstockList").flexigrid(option);
            $("#btnQueryList").bind("click", function () {
                refreshbyclick();
            });
            //新增，删除，修改
            function toolbarItem_onclick(cmd, grid) {
                if (cmd == "Add") {
                    OpenModelWindow('@Url.Action("OutstockGroupEdit")', { width: 806, height: 487, caption: "新增食材出库",
                        onclose: refresh
                    });
                }
                else if (cmd == 'Edit') {
                    var ids = "";
                    if ($('.trSelected', grid).length == 0 || $('.trSelected', grid).length > 1) {
                        showLoadingMsg("请选择一行数据进行编辑", { left: 300, top: 2 }, true, 3000);
                        return false;
                    }
                    else {
                        var items = $('.trSelected', grid);
                        for (i = 0; i < items.length; i++) {
                            if (i == items.length - 1) {
                                ids += items[i].id.substr(3);
                            } else {
                                ids += items[i].id.substr(3) + ", ";
                            } //if 
                        } //for
                    }
                    OpenModelWindow('@Url.Action("OutstockGroupEdit")?id=' + ids,
                        {
                            width: 806,
                            height: 487,
                            caption: "维护食材出库",
                            onclose: refresh
                        });
                }

                else if (cmd == 'Delete') {
                    if ($('.trSelected', grid).length == 0) {
                        showLoadingMsg("请选择要删除的行", { left: 300, top: 2 }, true, 3000);
                        return false;
                    } else {
                        if (confirm("确定要删除吗?")) {
                            var rowcount = 0;
                            var items = $('.trSelected', grid);
                            for (var i = 0; i < items.length; i++) {
                                var id = items[i].id.substr(3);
                                $.ajax({
                                    url: '@Url.Action("Delete")',
                                    type: "POST",
                                    data: { id: id },
                                    async: false,
                                    success: function (data) {
                                        if (data) {
                                            rowcount = rowcount + data;
                                        }
                                    },
                                    error: function () {
                                    }
                                });
                            } //for
                            if ($("#orderno").val()) {
                                refresh();
                            }
                            else {
                                refreshbyclick();
                            }
                            showLoadingMsg("共有" + rowcount.toString() + "个食材被删除!", { left: 400, top: 6 }, true, 3000);
                        }
                    }
                }
            } // end of toolbarItem_onclick
            function refreshbyclick() {
                var idt = ($("#instockDt").val() == null) ? "" : $("#instockDt").val();
                var iname = ($("#Con_GoodsInfoId").val() == null) ? "" : $("#Con_GoodsInfoId").val();
                var enddt = ($("#endDt").val() == null) ? "" : $("#endDt").val();
                var wh = ($("#Warehouse").val() == -1) ? "" : $("#Warehouse").val();
                var gu = ($("#Group").val() == -1) ? "" : $("#Group").val();
                if ($("#Con_GoodsInfoGoodsName").val() == "") {
                    iname = "";
                }
                option.query = "";
                var v1 = " and 1=1 ";
                if (idt != "") {
                    v1 += " and OutstockDt>='" + idt + "' ";
                }
                if (enddt != "") {
                    v1 += " and OutstockDt<='" + enddt + "'";
                }
                if (iname != "") {
                    v1 += " and Goods_ID='" + iname + "'";
                }
                if (wh != "") {
                    v1 += " and Warehouse_ID='" + wh + "'";
                }
                if (gu != "") {
                    v1 += " and Group_ID='" + gu + "'";
                }
                option.query = v1;
                //                option.query = "and ((OutstockDt >= '" + idt + "') and (OutstockDt <='" + enddt + "')) and "
                //                            + "((Goods_ID = '" + iname + "') or ('" + iname + "'='')) and "
                //                            + "((Warehouse_ID = '" + wh + "') or ('" + wh + "'='')) and "
                //                            + "((Group_ID = '" + gu + "') or ('" + gu + "'=''))";
                option.newp = 0;
                $('#OutstockList').flexOptions(option).flexReload();
            }
            function refresh() {
                option.query = "and OrderNo = '" + $("#orderno").val() + "'";
                option.newp = 0;
                $("#OutstockList").flexOptions(option).flexReload();
            }

        });

      

    </script>
}
<div id="container">
    <div id="mainContent">
        <div id="title" class="title">
            食材出库列表</div>
        <div id="findDiv">
            @Html.Hidden("orderno")
            <table>
                <tr>
                    <td style="text-align: right; width: 80px;">
                        开始日期:
                    </td>
                    <td>@Html.TextBox("instockDt", DateTime.Now.Date.ToString("yyyy-MM-dd"), new { @ReadOnly = true })
                    </td>
                    <td style="text-align: right; width: 80px;">
                        结束日期:
                    </td>
                    <td>@Html.TextBox("endDt", DateTime.Now.Date.ToString("yyyy-MM-dd"), new { @ReadOnly = true })
                    </td>
                    <td>
                        &nbsp;&nbsp;&nbsp;食材名称：
                    </td>
                    <td>
                        @Html.Partial("RtnSpoAllGoodsList")
                    </td>
                </tr>
                <td style="text-align: right; width: 80px;">
                    仓库:
                </td>
                <td>@Html.DropDownList("Warehouse",
                                      ViewData["GetWarehouse"] as IEnumerable<SelectListItem>,
                                      new { @style = "width:128px; height:22px; font-size:13px; vertical-align:middle;" })
                </td>
                <td style="text-align: right; width: 80px;">
                    班组:
                </td>
                <td>@Html.DropDownList("Group",
                                 ViewData["GetGroup"] as IEnumerable<SelectListItem>,
                                 new { @style = "width:128px; height:22px; font-size:13px; vertical-align:middle;" })
                </td>
                @*<td style="text-align:right; width:80px;">供应商:</td>
                <td>
					@Html.DropDownList("Supplier",
                            ViewData["Supplier"] as IEnumerable<SelectListItem>,
                            new { @style = "width:158px; height:22px; font-size:13px; vertical-align:middle;" })
			    </td>*@
                <td>
                    <a id="btnQueryList" class="button" href="javascript:void(0);"><span>查 询</span></a>
                </td>
                </tr>
            </table>
        </div>
        <table id="OutstockList" style="display: none;">
        </table>
    </div>
</div>
